package space.sakana.edusysback.mapper.question;

import org.apache.ibatis.annotations.*;
import space.sakana.edusysback.entity.question.Question;
import space.sakana.edusysback.entity.question.type.*;

import java.util.List;

@Mapper
public interface QuestionMapper {

    @Select("select `id`, `title`, `type`, `sid`, `create`, `tid`, `diff` from question;")
    List<Question> selectAllQuestion();

    @Select("select `id`, `title`, `type`, `sid`, `create`, `tid`, `diff` from question where `id`=#{id};")
    Question selectQuestionById(int id);

    @Select("select `id`, `title`, `type`, `sid`, `create`, `tid`, `diff` from question where `sid`=#{sid};")
    Question selectQuestionBySid(int sid);

    @Insert("insert into question(`title`, `type`, `sid`, `create`, `tid`, `diff`) values(#{title}, #{type}, #{sid}, #{create}, #{tid}, #{diff});")
    @Options(useGeneratedKeys=true, keyProperty="id", keyColumn="id")
    int insertQuestion(Question question);

    @Update("update question set `title`=#{title}, `type`=#{type}, `sid`=#{sid}, `create`=#{create}, `tid`=#{tid}, `diff`=#{diff} where `id`=#{id};")
    int updateQuestion(Question question);

    @Insert("insert into question_a(`qid`, `title`, `sid`, `choice_a`, `choice_b`, `choice_c`, `choice_d`, `answer`) " +
            "values(#{qid}, #{title}, #{sid}, #{choice_a}, #{choice_b}, #{choice_c}, #{choice_d}, #{answer});")
    int insertQuestionA(SingleChoice parseObject);

    @Insert("insert into question_b(`qid`, `title`, `sid`, `choice_a`, `choice_b`, `choice_c`, `choice_d`, `answer`) " +
            "values(#{qid}, #{title}, #{sid}, #{choice_a}, #{choice_b}, #{choice_c}, #{choice_d}, #{answer});")
    int insertQuestionB(MultipleChoice multipleChoice);

    @Insert("insert into question_c(`qid`, `title`, `sid`, `answer`) values(#{qid}, #{title}, #{sid}, #{answer});")
    int insertQuestionC(TrueFalseQ trueFalseQ);

    @Insert("insert into question_d(`qid`, `title`, `sid`, `answer`) values(#{qid}, #{title}, #{sid}, #{answer});")
    int insertQuestionD(EssayQuestion essayQuestion);

    @Select("select `id`, `qid`, `title`, `sid`, `choice_a`, `choice_b`, `choice_c`, `choice_d`, `answer` from question_a where `qid`=#{qid};")
    SingleChoice selectQuestionAById(int id);

    @Update("update question_a set `qid`=#{qid}, `title`=#{title}, `sid`=#{sid}, `choice_a`=#{choice_a}, `choice_b`=#{choice_b}, `choice_c`=#{choice_c}, `choice_d`=#{choice_d}, `answer`=#{answer} where `id`=#{id};")
    int updateQuestionA(SingleChoice singleChoice);

    @Select("select `id`, `qid`, `title`, `sid`, `choice_a`, `choice_b`, `choice_c`, `choice_d`, `answer` from question_b where `qid`=#{qid};")
    MultipleChoice selectQuestionBById(int id);

    @Update("update question_b set `qid`=#{qid}, `title`=#{title}, `sid`=#{sid}, `choice_a`=#{choice_a}, `choice_b`=#{choice_b}, `choice_c`=#{choice_c}, `choice_d`=#{choice_d}, `answer`=#{answer} where `id`=#{id};")
    int updateQuestionB(MultipleChoice multipleChoice);

    @Select("select `id`, `qid`, `title`, `sid`, `answer` from question_c where `qid`=#{qid};")
    TrueFalseQ selectQuestionCById(int id);

    @Update("update question_c set `qid`=#{qid}, `title`=#{title}, `sid`=#{sid}, `answer`=#{answer} where `id`=#{id};")
    int updateQuestionC(TrueFalseQ trueFalseQ);

    @Select("select `id`, `qid`, `title`, `sid`, `answer` from question_d where `qid`=#{qid};")
    EssayQuestion selectQuestionDById(int id);

    @Update("update question_d set `qid`=#{qid}, `title`=#{title}, `sid`=#{sid}, `answer`=#{answer} where `id`=#{id};")
    int updateQuestionD(EssayQuestion questionBase);

    @Delete("delete from question where `id`=#{qid};")
    int deleteQuestionById(int qid);
}
